//
//  YBRefreshView.swift
//  Weibo
//
//  Created by yinbo on 2018/4/2.
//  Copyright © 2018年 yinbo. All rights reserved.
//

import UIKit

class YBRefreshView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    var refreshState:YBRefreshState = .Normal{
        didSet{
            switch refreshState {
            case .Normal:
                tipIcon?.isHidden = false
                Indicator?.stopAnimating()
                tipLab?.text = "继续使劲拉"
//                tipIcon.image = UIImage(named:"navigationbar_arrow_down")
                UIView.animate(withDuration: 0.25, animations: {
                    self.tipIcon?.transform = CGAffineTransform.identity

                })
                
                
            case .Pulling:
                tipLab?.text = "放手就刷新"
             UIView.animate(withDuration: 0.25, animations: {
                     self.tipIcon?.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI-0.001))
                })
                
                
//                tipIcon.image = UIImage(named:"navigationbar_arrow_up")
            case .WillRefresh:
                tipLab?.text = "正在刷新中..."
                tipIcon?.isHidden = true
                Indicator?.startAnimating()
                
            }
        }
    }
    //指示器
    @IBOutlet weak var Indicator: UIActivityIndicatorView?
    //提示图标
    @IBOutlet weak var tipIcon: UIImageView?
    //提示标签
    @IBOutlet weak var tipLab: UILabel?
    
    class func refreshView()->YBRefreshView{
        let nib = UINib(nibName: "YBMeiTuanRefreshView", bundle: nil)
        return nib.instantiate(withOwner: nil, options: nil)[0] as! YBRefreshView
    }
}
